﻿@model Fap.AspNetCore.ViewModel.JqGridViewModel

<title>
    <fap-multilang lang-key="entry_manage" default-content="入职管理"></fap-multilang>
</title>

<div class="row">
    <div class="col-xs-12">
        <div class="widget-box">
            <div class="widget-header widget-header-flat">
                <h4 class="widget-title">
                    <fap-multilang lang-key="offer_list" default-content="offer列表"></fap-multilang>
                </h4>

                <div class="widget-toolbar">
                    <a href="#" data-action="fullscreen" class="orange2">
                        <i class="ace-icon fa fa-expand"></i>
                    </a>
                </div>
                <div class="widget-toolbar">
                    <fap-button id="btnSendOffer" btn-tag="link" content="发送Offer" icon-before="fa fa-envelope blue" class-name="info"></fap-button>
                    <fap-button id="btnItemPreperation" btn-tag="link" content="物品准备" icon-before="fa fa-cart-plus blue" class-name="info"></fap-button>
                    <fap-button id="btnCheckInfo" btn-tag="link" content="信息核对" icon-before="fa fa-check-square  blue" class-name="info"></fap-button>
                    <fap-button id="btnEntry" btn-tag="link" content="入职" icon-before="fa fa-user-plus blue" class-name="info"></fap-button>
                </div>
                <div class="widget-toolbar">
                    <fap-button id="btnInvalidOffer" btn-tag="link" content="作废" icon-before="fa  fa-times-circle blue" class-name="info"></fap-button>
                </div>
            </div>
            <div class="widget-body">

                <div class="widget-main">
                    <fap-grid id="offer" grid-model="Model" wrapper="widget-main" register-authority="false" oper-chart="true" view-records="true" shrink-fit="false"></fap-grid>

                    <!-- /.row -->
                </div>
            </div>
        </div>
    </div>

</div>

<script>
    var scripts = [null, "/Scripts/Workflow/business.js?v=2", null]
    $('.page-content-area').ace_ajax('loadScripts', scripts, function () {
        jQuery(function ($) {
            $(document).one('ajaxloadstart.page', function (e) {
            })
            $("#btnInvalidOffer").on(ace.click_event, function () {
                bootbox.confirm($.lang("invalid", "作废"), function (result) {
                    if (result) {
                        var rw = getSelectedRow("grid-offer");
                        if (rw == null) {
                            return;
                        }
                        $.post(basePath + "/Recruit/Api/OfferStatus", { fid: rw.Fid, status: 'Invalid' }, function (rv) {
                            if (rv.success) {
                                refreshGrid("grid-offer");
                            } else {
                                bootbox.alert(rv.msg);
                            }
                        })
                    }
                })

            })
            $("#btnSendOffer").on(ace.click_event, function () {
                var rw = getSelectedRow("grid-offer");
                if (rw == null) {
                    return;
                }
                bootboxWindow($.lang("send_offer_notice", "发送Offer通知"), basePath + "/Recruit/Manage/OfferNotice",
                    {
                        ok: {
                            label: $.lang("ok", "确定"),
                            className: "btn-primary btn-link",
                            callback: function () {
                                return sendOfferNotice(rw.Fid, function () {
                                    refreshGrid("grid-offer");
                                });
                            }
                        }
                    }, { offerUid: rw.Fid });
            })
            $("#btnItemPreperation").on(ace.click_event, function () {
                var rw = getSelectedRow("grid-offer");
                if (rw == null) {
                    return;
                }
                bootboxWindow($.lang("item_preparation", "物品准备"), basePath + "/Recruit/Manage/ItemPreparation", null,
                    { offerUid: rw.Fid, offerName: rw.EmpName, menuUrl: "~/Recruit/Manage/Entry" });
            })
            $("#btnCheckInfo").on(ace.click_event, function () {
                var rw = getSelectedRow("grid-offer");
                if (rw == null) {
                    return;
                }
                if (rw.OfferStatus === "InfoMaintenance" || rw.OfferStatus === "Checked") {
                    bootboxWindow($.lang("check_information", "信息核对"), basePath + "/Recruit/Manage/CheckProfile",
                        {
                            ok: {
                                label: $.lang("ok", "确定"),
                                className: "btn-primary btn-link",
                                callback: function () {
                                    return Persistence("frm-profile", "EmpEntryInfo", null, function () {
                                        if (rw.OfferStatus === "InfoMaintenance") {
                                            $.post(basePath + "/Recruit/Api/OfferStatus", { fid: rw.Fid, status: 'Checked' }, function (rv) {
                                                if (rv.success) {
                                                    refreshGrid("grid-offer");
                                                } else {
                                                    bootbox.alert(rv.msg);
                                                }
                                            });
                                        }
                                    })
                                }
                            }
                        },
                        { offerUid: rw.Fid, formStatus: 2 });
                } else if (rw.OfferStatus === "Entry") {
                    bootboxWindow($.lang("view_information", "查看信息"), basePath + "/Recruit/Manage/CheckProfile",
                        null,
                        { offerUid: rw.Fid, formStatus:3 });
                } else {
                    $.msg("只有员工维护完信息以后方能核对");
                }
            })

            $("#btnEntry").on(ace.click_event, function () {
                var rw = getSelectedRow("grid-offer");
                if (rw == null) {
                    return;
                }
                if (rw.OfferStatus === "Checked") {
                    bootboxWindow($.lang("entry", "入职"), basePath + "/Recruit/Manage/CheckProfile",
                        {
                            ok: {
                                label: $.lang("entry", "入职"),
                                className: "btn-primary btn-link",
                                callback: function () {
                                    entry(rw.Fid);
                                    refreshGrid("grid-offer");
                                    //return false;
                                }
                            }
                        },
                        { offerUid: rw.Fid, formStatus: 3 });
                } else if (rw.OfferStatus === "Entry") {
                    $.msg("已经完成了入职");
                } else {
                    $.msg("信息核对后才能入职");
                }
            })
        })
    })
</script>